cmake_minimum_required(VERSION 3.15)
project(DicomTools CXX)
set(TARGET_NAME DicomTools)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)  # build DicomTools shared library
if(NOT ${BUILD_SHARED_LIBS})
    message(FATAL_ERROR "cannot build ${TARGET_NAME} as a static library")
endif()

find_package(freetype CONFIG REQUIRED PATHS "F:/ci/CI_HOME/ci_cache/windows_x86_64_msvc16_md/freetype-2.10.4-static")
find_package(harfbuzz CONFIG REQUIRED PATHS "F:/ci/CI_HOME/ci_cache/windows_x86_64_msvc16_md/harfbuzz-2.7.4-static")
find_package(Eigen3 CONFIG REQUIRED PATHS "F:/ci/CI_HOME/ci_cache/windows_x86_64_msvc16_md/Eigen3-3.3.9")
set(OpenCV_STATIC ON)  # use opencv static library
find_package(OpenCV CONFIG REQUIRED PATHS "F:/ci/CI_HOME/ci_cache/windows_x86_64_msvc16_md/OpenCV-freetype-4.5.5")
add_definitions(-DDCM_DEV_TOOLKIT)  # enable dcmtk toolkit
find_package(DCMTK CONFIG REQUIRED PATHS "F:/ci/CI_HOME/ci_cache/windows_x86_64_msvc16_md/DCMTK-OpenSSL-3.6.7-static")
find_package(nlohmann_json CONFIG REQUIRED PATHS "F:/ci/CI_HOME/ci_cache/windows_x86_64_msvc16_md/nlohmann_json-3.11.2")

file(GLOB_RECURSE "SOURCE_FILE"
    ${PROJECT_SOURCE_DIR}/include/*
    ${PROJECT_SOURCE_DIR}/src/*
)

add_library(${TARGET_NAME} ${SOURCE_FILE})

set(TARGET_INCLUDE_DIRS
    ${CMAKE_CURRENT_LIST_DIR}/src/dataset
    ${CMAKE_CURRENT_LIST_DIR}/src/network
    ${CMAKE_CURRENT_LIST_DIR}/src/image
    ${CMAKE_CURRENT_LIST_DIR}/src/print
    ${CMAKE_CURRENT_LIST_DIR}/src/util
    ${CMAKE_CURRENT_LIST_DIR}/src/interface
    ${CMAKE_CURRENT_LIST_DIR}/include
)
string(REPLACE ";" "$<SEMICOLON>" _include_dirs "${TARGET_INCLUDE_DIRS}")
target_include_directories(${TARGET_NAME} SYSTEM
    PRIVATE
        ${TARGET_INCLUDE_DIRS}
    INTERFACE
        "$<BUILD_INTERFACE:${_include_dirs}>"
        "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>"
)

target_link_libraries(${TARGET_NAME}
    PRIVATE
        DCMTK::DCMTK
        nlohmann_json::nlohmann_json
        opencv_freetype
        opencv_highgui
)
set_target_properties(${TARGET_NAME}
    PROPERTIES
        POSITION_INDEPENDENT_CODE "${BUILD_SHARED_LIBS}"
        LINK_FLAGS "/ignore:4099"
)

# test
enable_testing()
add_subdirectory(test)
